package com.fs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.pojo.Order;
import com.fs.pojo.Outsto;
import com.fs.pojo.ReturnToVendor;
import com.fs.service.ReturnToService;
import com.fs.util.ResponseDataUtil;
import com.fs.vo.Condition;
import com.fs.vo.ResponseData;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hyy
 * @version 1.0
 * @date 2024/10/22 17:20
 */
@RestController
@RequestMapping("/sales/return")
public class ReturnToController {
    @Autowired
    private ReturnToService returnToService;

    /**
     * 表格查询信息
     * @param condition
     * @return
     */
    @PostMapping("/query")
    private ResponseData<PageInfo<Order>> queryAll(@RequestBody Condition<ReturnToVendor> condition){
        Page<ReturnToVendor> querylist = returnToService.querylist(condition);
        return querylist!=null? ResponseDataUtil.buildOk(querylist): ResponseDataUtil.buildFail(null);
    }
    /**
     * 通过id获取退货order订单信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    private  ResponseData<Order> queryOrderById(@PathVariable Integer id){
        ReturnToVendor order = returnToService.getOrderById(id);
        return order!=null?ResponseDataUtil.buildOk(210,"查询成功",order):ResponseDataUtil.buildFail(null);
    }

    /**
     * 添加退货信息
     * @param returnToVendor
     * @return
     */
    @PostMapping("/add")
    private  ResponseData addReturnTo(@RequestBody ReturnToVendor returnToVendor){
        Integer i = returnToService.addReturnToVendor(returnToVendor);
        return i!=0?ResponseDataUtil.buildOk(210,"插入成功"):ResponseDataUtil.buildFail(null);
    }

    /**
     * 更新退货状态
     * @param returnToVendor
     * @return
     */
    @PostMapping("/update")
    public ResponseData updateReturn(@RequestBody ReturnToVendor returnToVendor){
        return returnToService.updatReturnToVendor(returnToVendor)!=0? ResponseDataUtil.buildOk("修改成功"):ResponseDataUtil.buildFail(null);
    }

    /**
     * 删除退货单信息
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    private  ResponseData<Order> delOrderById(@PathVariable Integer id){
        Boolean order = returnToService.delReturnToVendor(id);
        return order?ResponseDataUtil.buildOk(204,"删除成功"):ResponseDataUtil.buildFail(null);
    }
}
